#!/bin/bash

# shellcheck disable=SC1091
. ../../lib/shflags

DEFINE_string "conn" '' 'jdbc:mysql://192.168.31.149:3307/xxl-job?characterEncoding=UTF-8' 'c'
DEFINE_integer "expose" 8090 'expose port' 'e'
DEFINE_string "username" 'root' 'mysql username' 'u'
DEFINE_string "password" '12345678' 'mysql password' 'p'
DEFINE_string "version" '3.1.1' 'mysql version' 'v'
DEFINE_string "accessToken" "$(cat /proc/sys/kernel/random/uuid)" 'xxl-job.accessToken' 't'
DEFINE_string "logdir" '' 'mysql version' 'l'

# 解析命令行参数
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

echo "mysql, ${FLAGS_conn} expose ${FLAGS_expose} version ${FLAGS_version} accessToken ${FLAGS_accessToken} logdir ${FLAGS_logdir} ."

docker run --name xxl-job-admin \
  --network 1panel-network \
  -v /tmp:/data/applogs \
  -p "${FLAGS_expose}":8080 \
  -e PARAMS="\
    --spring.datasource.url=${FLAGS_conn} \
    --spring.datasource.username=${FLAGS_username} \
    --spring.datasource.password=${FLAGS_password} \
    --xxl.job.accessToken=${FLAGS_accessToken}" \
  -d xuxueli/xxl-job-admin:${FLAGS_version}